﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace VPN.Querier
{
    public class MailHelper
    {
        public static void Send(string account, string password, DateTime expireDate, string[] recievers, string templatePath)
        {
            #region Generate Mail body
            string s = string.Empty;
            //using (System.IO.StreamReader sr = new System.IO.StreamReader(templatePath))
            //{
            //    s = sr.ReadToEnd();
            //    s = s.Replace("{Account}", account);
            //    s = s.Replace("{Date}", DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
            //    s = s.Replace("{Password}", password);
            //    s = s.Replace("{ExpireDate}", expireDate.ToString("yyyy-MM-dd HH:mm:ss"));
            //}

            MailMessage m = new MailMessage();
            m.BodyEncoding = Encoding.UTF8;
            m.Subject = "感谢您购买VPN帐号，以下是您的帐号信息"; 
            foreach (string r in recievers)
            {
                m.To.Add(new MailAddress(r));
            }
            m.IsBodyHtml = true;
            m.Body = "ABC";
            m.Sender = new MailAddress("raysensi@gmail.com");
            m.From = new MailAddress("reynhalt@gmail.com");
            #endregion

            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
            smtp.EnableSsl = true;            
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(m.Sender.Address, "dad491117");
            smtp.Send(m);
        }


    }
}
